//
//  ShadowViewController.m
//  UILbrary
//
//  Created by Apple on 2021/9/26.
//  Copyright © 2021 mac. All rights reserved.
//

#import "ShadowViewController.h"

@interface ShadowViewController ()

@end

@implementation ShadowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"阴影";
    
    [self p_setupSubViews_4];
}

//MARK: -
//MARK: 参考文章https://www.jianshu.com/p/9f73bc843d00
//MARK: -

- (void)p_setupSubViews_0 {
    self.view.backgroundColor = [UIColor whiteColor];
    [self p_setupViewWithY:100 shadowColor:[UIColor redColor]];
    [self p_setupViewWithY:170 shadowColor:[UIColor blueColor]];
    [self p_setupViewWithY:240 shadowColor:[UIColor yellowColor]];
}

- (void)p_setupViewWithY:(CGFloat)y shadowColor:(UIColor *)shadowColor {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, y, [UIScreen mainScreen].bounds.size.width - 60, 50)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    view.layer.shadowOpacity = 1;
    view.layer.shadowColor = shadowColor.CGColor;
}

//MARK: - 透明 shadowOpacity

- (void)p_setupSubViews_1 {
    self.view.backgroundColor = [UIColor whiteColor];
    [self p_setupViewWithY:100 shadowOpacity:0.2];
    [self p_setupViewWithY:170 shadowOpacity:0.6];
    [self p_setupViewWithY:240 shadowOpacity:0.9];
}

- (void)p_setupViewWithY:(CGFloat)y shadowOpacity:(float)shadowOpacity {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, y, [UIScreen mainScreen].bounds.size.width - 60, 50)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    view.layer.shadowOpacity = shadowOpacity;
}

//MARK: - 偏移 shadowOffset

- (void)p_setupSubViews_2 {
    self.view.backgroundColor = [UIColor whiteColor];
    [self p_setupViewWithY:100 shadowOffset:CGSizeMake(0, 0)];
    [self p_setupViewWithY:170 shadowOffset:CGSizeMake(5, 0)];
    [self p_setupViewWithY:240 shadowOffset:CGSizeMake(-5, 0)];
    [self p_setupViewWithY:310 shadowOffset:CGSizeMake(0, 5)];
    [self p_setupViewWithY:380 shadowOffset:CGSizeMake(0, -5)];
    [self p_setupViewWithY:450 shadowOffset:CGSizeMake(5, 5)];
    [self p_setupViewWithY:520 shadowOffset:CGSizeMake(-5, -5)];
}

- (void)p_setupViewWithY:(CGFloat)y shadowOffset:(CGSize)shadowOffset {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, y, [UIScreen mainScreen].bounds.size.width - 60, 50)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    view.layer.shadowOpacity = 1;
    view.layer.shadowOffset = shadowOffset;
}

//MARK: - 圆角 宽度 shadowRadius

- (void)p_setupSubViews_3 {
    self.view.backgroundColor = [UIColor whiteColor];
    [self p_setupViewWithY:100 shadowRadius:0];
    [self p_setupViewWithY:170 shadowRadius:3.0];
    [self p_setupViewWithY:240 shadowRadius:10.0];

}

- (void)p_setupViewWithY:(CGFloat)y shadowRadius:(CGFloat)shadowRadius {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, y, [UIScreen mainScreen].bounds.size.width - 60, 50)];
    view.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:view];
    view.layer.shadowOpacity = 1;
    view.layer.shadowOffset = CGSizeMake(0, 0);
    view.layer.shadowRadius = shadowRadius;
}

//MARK: -  shadowPath

- (void)p_setupSubViews_4 {
    self.view.backgroundColor = [UIColor whiteColor];
    [self p_setupViewWithY1:100];
    [self p_setupViewWithY2:170];
    [self p_setupViewWithY3:240];//贝塞尔曲线未闭合
}

- (void)p_setupViewWithY1:(CGFloat)y {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, y, [UIScreen mainScreen].bounds.size.width - 60, 50)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    view.layer.shadowOpacity = 1;
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:view.bounds];
    view.layer.shadowPath = path.CGPath;
}

- (void)p_setupViewWithY2:(CGFloat)y {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, y, [UIScreen mainScreen].bounds.size.width - 60, 50)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    view.layer.shadowOpacity = 1;
    UIBezierPath *path = [UIBezierPath bezierPath];
    //左上角
    [path moveToPoint:CGPointMake(0, -10)];
    //左下角
    [path addLineToPoint:CGPointMake(0, view.frame.size.height + 10)];
    //右下角
    [path addLineToPoint:CGPointMake(view.frame.size.width, view.frame.size.height + 10)];
    //右上角
    [path addLineToPoint:CGPointMake(view.frame.size.width, -10)];
    [path addLineToPoint:CGPointMake(0, 0)];
    view.layer.shadowPath = path.CGPath;
}

- (void)p_setupViewWithY3:(CGFloat)y {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, y, [UIScreen mainScreen].bounds.size.width - 60, 50)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    view.layer.shadowOpacity = 1;
    view.layer.shadowOffset = CGSizeMake(0, 0);
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(-5, 0)];
    [path addLineToPoint:CGPointMake(-5, view.frame.size.height)];
    [path addLineToPoint:CGPointMake(view.frame.size.width, view.frame.size.height)];
    [path addLineToPoint:CGPointMake(view.frame.size.width, 0)];
    view.layer.shadowPath = path.CGPath;
}

@end
